package com.unswift.utils;

import java.io.File;
import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.math.BigDecimal;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.stream.Collectors;

import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.util.SystemPropertyUtils;

import com.unswift.annotation.api.Api;
import com.unswift.annotation.api.ApiConstructor;
import com.unswift.annotation.api.ApiEntity;
import com.unswift.annotation.api.ApiField;
import com.unswift.annotation.api.ApiMethod;
import com.unswift.enums.ExceptionEnum;
import com.unswift.exception.ClassException;
import com.unswift.exception.CoreException;

@SuppressWarnings("unchecked")
@Api(value="java反射公共操作类，可执行类实例化，获取指定属性，执行类的方法等操作", author="unswift", date="2022-12-16", version="1.0.0")
public final class ClassUtils {

	@ApiField("类路径表达式")
	protected static final String DEFAULT_RESOURCE_PATTERN = "**/*.class";
	
	@ApiMethod(value="根据反射类对象实例化对象", params=@ApiField("反射类对象"), returns=@ApiField("实例化后的对象"))
	public static <T> T newInstance(Class<T> tclass){
		try {
			Constructor<T> constructor = tclass.getDeclaredConstructor();
			constructor.setAccessible(true);
			return constructor.newInstance();
		} catch (Exception e) {
			e.printStackTrace();
			throw new ClassException(ExceptionEnum.CLASS_INSTANCE_EXCEPTION.getCode(), String.format(ExceptionEnum.CLASS_INSTANCE_EXCEPTION.getMessage(), tclass.getName(), e.getMessage()), e);
		}
	}
	
	@ApiMethod(value="根据类路径实例化对象", params=@ApiField("反射类对象路径"), returns=@ApiField("实例化后的对象"))
	public static <T> T newInstance(String tclassName){
		return (T)newInstance(forName(tclassName));
	}
	
	@ApiMethod(value="根据类装载器和类路径实例化对象", params={@ApiField("类装载器"), @ApiField("反射类对象路径")}, returns=@ApiField("实例化后的对象"))
	public static <T> T newInstance(ClassLoader classLoader, String tclassName){
		return (T)newInstance(forName(classLoader, tclassName));
	}
	
	@ApiMethod(value="根据反射类对象及入参实例化对象", params={@ApiField("反射类对象"), @ApiField("构造方法的参数类型数组"), @ApiField("参数数组")}, returns=@ApiField("实例化后的对象"))
	public static <T> T newInstance(Class<T> tclass, Class<?>[] paramClasses, Object...params){
		try {
			Constructor<T> constructor = tclass.getConstructor(paramClasses);
			return constructor.newInstance(params);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ClassException(ExceptionEnum.CLASS_INSTANCE_EXCEPTION.getCode(), String.format(ExceptionEnum.CLASS_INSTANCE_EXCEPTION.getMessage(), tclass.getName(), e.getMessage()), e);
		}
	}
	
	@ApiMethod(value="根据类路径及入参实例化对象", params={@ApiField("类路径"), @ApiField("构造方法的参数类型数组"), @ApiField("参数数组")}, returns=@ApiField("实例化后的对象"))
	public static <T> T newInstance(String tclassName, Class<?>[] paramClasses, Object...params){
		return (T)newInstance(forName(tclassName), paramClasses, params);
	}
	
	@ApiMethod(value="根据类路径生产反射类对象", params=@ApiField("类路径"), returns=@ApiField("反射类对象"))
	public static <T> Class<T> forName(String className){
		try {
			return (Class<T>)Class.forName(className);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ClassException(ExceptionEnum.CLASS_FOR_NAME.getCode(), String.format(ExceptionEnum.CLASS_FOR_NAME.getMessage(), className, e.getMessage()), e);
		}
	}
	
	@ApiMethod(value="根据类装载器和类路径生产反射类对象", params={@ApiField("类装在器"), @ApiField("类路径")}, returns=@ApiField("反射类对象"))
	public static <T> Class<T> forName(ClassLoader classLoader, String className){
		try {
			if(ObjectUtils.isNotEmpty(classLoader)){
				return (Class<T>)classLoader.loadClass(className);
			}else{
				return (Class<T>)Class.forName(className);
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new ClassException(ExceptionEnum.CLASS_FOR_NAME.getCode(), String.format(ExceptionEnum.CLASS_FOR_NAME.getMessage(), className, e.getMessage()), e);
		}
	}
	
	@ApiMethod(value="查找反射类对象的所有属性，不包含常量及静态属性，父类的属性排在前面", params=@ApiField("反射类对象"), returns=@ApiField("属性对象列表"))
	public static List<Field> getFieldList(Class<?> sourceClass){
		List<Field> fieldList=new ArrayList<Field>(), parentFieldList;
		Class<?> superClass=sourceClass;
		Field[] fields;
		boolean loadParent=false;
		while(ObjectUtils.isNotEmpty(superClass) && !superClass.equals(Object.class)){
			fields=superClass.getDeclaredFields();
			if(ObjectUtils.isNotEmpty(fields)){
				if(loadParent) {
					parentFieldList=new ArrayList<Field>();
				}else {
					parentFieldList=null;
				}
				for (Field field : fields) {
					if(!Modifier.isFinal(field.getModifiers()) && !Modifier.isStatic(field.getModifiers())){
						if(loadParent) {
							parentFieldList.add(field);
						}else {
							fieldList.add(field);
						}
					}
				}
				if(loadParent && ObjectUtils.isNotEmpty(parentFieldList)) {
					if(fieldList.size()>0) {
						fieldList.addAll(0, parentFieldList);
					}else {
						fieldList.addAll(parentFieldList);
					}
				}
			}
			superClass=superClass.getSuperclass();
			loadParent=true;
		}
		return fieldList;
	}
	
	@ApiMethod(value="在反射类对象中查找指定属性", params={@ApiField("反射类对象"), @ApiField("属性名称")}, returns=@ApiField("属性对象"))
	public static Field getField(Class<?> sourceClass, String fieldName){
		Class<?> superClass=sourceClass;
		Field field;
		while(!superClass.equals(Object.class)){
			try {
				field=superClass.getDeclaredField(fieldName);
				if(ObjectUtils.isNotEmpty(field)){
					return field;
				}
			} catch (Exception e) {}
			superClass=superClass.getSuperclass();
		}
		return null;
	}
	
	@ApiMethod(value="获取对象指定属性值", params={@ApiField("Pojo对象"), @ApiField("属性对象")}, returns=@ApiField("属性值"))
	public static <T> T get(Object source, Field field){
		try {
			field.setAccessible(true);
			return (T)field.get(source);
		} catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.exception("class.get.field.exception", e, source.getClass().getName(), field.getName(), e.getMessage());
		}
		
	}
	
	@ApiMethod(value="获取对象指定属性值", params={@ApiField("Pojo对象"), @ApiField("属性名称")}, returns=@ApiField("属性值"))
	public static <T> T get(Object source, String fieldName){
		Field field=getField(source.getClass(), fieldName);
		if(ObjectUtils.isNull(field)){
			throw ExceptionUtils.message("class.get.field.exception", source.getClass().getName(), fieldName, "字段名称为空");
		}
		return get(source, field);
	}
	
	@ApiMethod(value="设置对象指定属性值", params={@ApiField("Pojo对象"), @ApiField("属性对象"), @ApiField("属性值")})
	public static void set(Object source, Field field, Object value){
		try {
			field.setAccessible(true);
			field.set(source, value);
		} catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.exception("class.set.field.exception", e, source.getClass().getName(), field.getName(), e.getMessage());
		}
		
	}
	
	@ApiMethod(value="设置对象指定属性值", params={@ApiField("Pojo对象"), @ApiField("属性名称"), @ApiField("属性值")})
	public static void set(Object source, String fieldName, Object value){
		Field field=getField(source.getClass(), fieldName);
		if(ObjectUtils.isNull(field)){
			throw ExceptionUtils.message("class.get.field.exception", source.getClass().getName(), "空", "字段名称为空");
		}
		set(source, field, value);
	}
	
	@ApiMethod(value="判断在对象中是否存在指定属性", params={@ApiField("Pojo对象"), @ApiField("属性名称")}, returns=@ApiField("是否存在，true：存在，false：不存在"))
	public static boolean existsField(Object source, String fieldName){
		return existsField(source.getClass(), fieldName);
	}
	
	@ApiMethod(value="判断在反射类对象中是否存在指定属性", params={@ApiField("反射类对象"), @ApiField("属性名称")}, returns=@ApiField("是否存在，true：存在，false：不存在"))
	public static boolean existsField(Class<?> sourceClass, String fieldName){
		try {
			Field field=null;
			Class<?> superClass=sourceClass;
			while(!superClass.equals(Object.class) && ObjectUtils.isEmpty(field)){
				try {
					field=superClass.getDeclaredField(fieldName);
				} catch (NoSuchFieldException e) {}
				superClass=superClass.getSuperclass();
			}
			return ObjectUtils.isNotEmpty(field);
		} catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.exception("class.find.field.exception", e, sourceClass.getName(), fieldName, e.getMessage());
		}
	}
	
	@ApiMethod(value="在反射类对象中执行无参受保护的静态方法", params={@ApiField("反射类对象"), @ApiField("静态方法名称")}, returns=@ApiField("执行结果"))
	public static <T> T invokeDeclared(Class<?> source, String methodName){
		try {
		Method method = source.getDeclaredMethod(methodName);
		method.setAccessible(true);
		return (T)method.invoke(null);
		} catch(InvocationTargetException e) {
			Throwable targetException = ((InvocationTargetException) e).getTargetException();
			throw ExceptionUtils.exception("class.invoke.method.exception", targetException, source.getClass().getName(), methodName, targetException.getMessage());
		}  catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.exception("class.invoke.static.method.exception", e, source.getName(), methodName, e.getMessage());
		}
	}
	
	@ApiMethod(value="在反射类对象中执行有参受保护的静态方法", params={@ApiField("反射类对象"), @ApiField("静态方法名称"), @ApiField("参数反射类对象数组"), @ApiField("参数数组")}, returns=@ApiField("执行结果"))
	public static <T> T invokeDeclared(Class<?> source, String methodName, Class<?> paramClasses, Object...args){
		try {
			Method method = source.getDeclaredMethod(methodName, paramClasses);
			method.setAccessible(true);
			return (T)method.invoke(null, args);
		} catch(InvocationTargetException e) {
			Throwable targetException = ((InvocationTargetException) e).getTargetException();
			throw ExceptionUtils.exception("class.invoke.method.exception", targetException, source.getClass().getName(), methodName, targetException.getMessage());
		}  catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.exception("class.invoke.static.method.exception", e, source.getName(), methodName, e.getMessage());
		}
	}
	
	@ApiMethod(value="在对象中执行无参受保护的方法", params={@ApiField("对象"), @ApiField("方法名称")}, returns=@ApiField("执行结果"))
	public static <T> T invokeDeclared(Object source, String methodName){
		try {
			Method method = source.getClass().getDeclaredMethod(methodName);
			method.setAccessible(true);
			return (T)method.invoke(source);
		} catch(InvocationTargetException e) {
			Throwable targetException = ((InvocationTargetException) e).getTargetException();
			throw ExceptionUtils.exception("class.invoke.method.exception", targetException, source.getClass().getName(), methodName, targetException.getMessage());
		}  catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.exception("class.invoke.method.exception", e, source.getClass().getName(), methodName, e.getMessage());
		}
	}
	
	@ApiMethod(value="在对象中执行有参受保护的方法", params={@ApiField("对象"), @ApiField("方法名称"), @ApiField("参数反射类对象数组"), @ApiField("参数数组")}, returns=@ApiField("执行结果"))
	public static <T> T invokeDeclared(Object source, String methodName, Class<?>[] paramClasses, Object...args){
		try {
			Method method = source.getClass().getDeclaredMethod(methodName, paramClasses);
			method.setAccessible(true);
			return (T)method.invoke(source, args);
		} catch(InvocationTargetException e) {
			Throwable targetException = ((InvocationTargetException) e).getTargetException();
			throw ExceptionUtils.exception("class.invoke.method.exception", targetException, source.getClass().getName(), methodName, targetException.getMessage());
		}  catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.exception("class.invoke.method.exception", e, source.getClass().getName(), methodName, e.getMessage());
		}
	}
	
	
	@ApiMethod(value="在对象中执行无参受保护的方法，有可能source是sourceClass类类型表示的子类", params={@ApiField("对象"), @ApiField("对象或其父类反射对象"), @ApiField("方法名称")}, returns=@ApiField("执行结果"))
	public static <T> T invokeDeclared(Object source, Class<?> sourceClass, String methodName){
		try {
			Method method = sourceClass.getDeclaredMethod(methodName);
			method.setAccessible(true);
			return (T)method.invoke(source);
		} catch(InvocationTargetException e) {
			Throwable targetException = ((InvocationTargetException) e).getTargetException();
			throw ExceptionUtils.exception("class.invoke.method.exception", targetException, source.getClass().getName(), methodName, targetException.getMessage());
		}  catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.exception("class.invoke.method.exception", e, source.getClass().getName(), methodName, e.getMessage());
		}
	}
	
	@ApiMethod(value="在对象中执行有参受保护的方法", params={@ApiField("对象"), @ApiField("方法名称"), @ApiField("参数反射类对象数组"), @ApiField("对象或其父类反射对象"), @ApiField("参数数组")}, returns=@ApiField("执行结果"))
	public static <T> T invokeDeclared(Object source, Class<?> sourceClass, String methodName, Class<?>[] paramClasses, Object...args){
		try {
			Method method = sourceClass.getDeclaredMethod(methodName, paramClasses);
			method.setAccessible(true);
			return (T)method.invoke(source, args);
		} catch(InvocationTargetException e) {
			Throwable targetException = ((InvocationTargetException) e).getTargetException();
			throw ExceptionUtils.exception("class.invoke.method.exception", targetException, source.getClass().getName(), methodName, targetException.getMessage());
		}  catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.exception("class.invoke.method.exception", e, source.getClass().getName(), methodName, e.getMessage());
		}
	}
	
	@ApiMethod(value="在反射类对象中执行无参静态方法", params={@ApiField("反射类对象"), @ApiField("静态方法名称")}, returns=@ApiField("执行结果"))
	public static <T> T invoke(Class<?> source, String methodName){
		try {
			return (T)source.getMethod(methodName).invoke(null);
		} catch(InvocationTargetException e) {
			Throwable targetException = ((InvocationTargetException) e).getTargetException();
			throw ExceptionUtils.exception("class.invoke.method.exception", targetException, source.getClass().getName(), methodName, targetException.getMessage());
		}  catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.exception("class.invoke.static.method.exception", e, source.getName(), methodName, e.getMessage());
		}
	}
	
	@ApiMethod(value="在反射类对象中执行有参静态方法", params={@ApiField("反射类对象"), @ApiField("静态方法名称"), @ApiField("参数反射类对象数组"), @ApiField("参数数组")}, returns=@ApiField("执行结果"))
	public static <T> T invoke(Class<?> source, String methodName, Class<?> paramClasses, Object...args){
		try {
			return (T)source.getMethod(methodName, paramClasses).invoke(null, args);
		} catch(InvocationTargetException e) {
			Throwable targetException = ((InvocationTargetException) e).getTargetException();
			throw ExceptionUtils.exception("class.invoke.method.exception", targetException, source.getClass().getName(), methodName, targetException.getMessage());
		}  catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.exception("class.invoke.static.method.exception", e, source.getName(), methodName, e.getMessage());
		}
	}
	
	@ApiMethod(value="在对象中执行无参方法", params={@ApiField("对象"), @ApiField("方法名称")}, returns=@ApiField("执行结果"))
	public static <T> T invoke(Object source, String methodName){
		try {
			return (T)source.getClass().getMethod(methodName).invoke(source);
		} catch(InvocationTargetException e) {
			Throwable targetException = ((InvocationTargetException) e).getTargetException();
			throw ExceptionUtils.exception("class.invoke.method.exception", targetException, source.getClass().getName(), methodName, targetException.getMessage());
		}  catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.exception("class.invoke.method.exception", e, source.getClass().getName(), methodName, e.getMessage());
		}
	}
	
	@ApiMethod(value="在对象中执行有参方法", params={@ApiField("对象"), @ApiField("方法名称"), @ApiField("参数反射类对象数组"), @ApiField("参数数组")}, returns=@ApiField("执行结果"))
	public static <T> T invoke(Object source, String methodName, Class<?>[] paramClasses, Object...args){
		try {
			return (T)source.getClass().getMethod(methodName, paramClasses).invoke(source, args);
		} catch(InvocationTargetException e) {
			Throwable targetException = ((InvocationTargetException) e).getTargetException();
			throw ExceptionUtils.exception("class.invoke.method.exception", targetException, source.getClass().getName(), methodName, targetException.getMessage());
		}  catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.exception("class.invoke.method.exception", e, source.getClass().getName(), methodName, e.getMessage());
		}
	}
	
	@ApiMethod(
			value="在对象类中执行有参方法，此方法具有模糊匹配的功能，先找最符合条件的，找不到则会把参数反射类对象父类对象作为参数查找", 
			params={@ApiField("对象类型"), @ApiField("方法名称"), @ApiField("参数反射类对象Map，Map的key为参数的位置，value为参数反射类对象，此Map的key并不会记录所有的参数类型，只是有必要的记录或者有限的记录"), @ApiField("参数值数组")}, 
			returns=@ApiField("执行结果")
		)
		public static <T> T invoke(Class<?> source, String methodName, Map<Integer, Class<?>> defaultParamClasses, Object...args){
			try {
				if(ObjectUtils.isEmpty(args)){
					return invoke(source, methodName);
				}
				ParamClass[] argsClassArray=getClassArray(defaultParamClasses, args);
				return (T)matchMethod(source, methodName, args, argsClassArray).invoke(null, args);
			} catch(InvocationTargetException e) {
				Throwable targetException = ((InvocationTargetException) e).getTargetException();
				throw ExceptionUtils.exception("class.invoke.method.exception", targetException, source.getClass().getName(), methodName, targetException.getMessage());
			} catch (Exception e) {
				e.printStackTrace();
				throw ExceptionUtils.exception("class.invoke.method.exception", e, source.getClass().getName(), methodName, e.getMessage());
			}
		}
	
	@ApiMethod(
		value="在对象中执行有参方法，此方法具有模糊匹配的功能，先找最符合条件的，找不到则会把参数反射类对象父类对象作为参数查找", 
		params={@ApiField("对象"), @ApiField("方法名称"), @ApiField("参数反射类对象Map，Map的key为参数的位置，value为参数反射类对象，此Map的key并不会记录所有的参数类型，只是有必要的记录或者有限的记录"), @ApiField("参数值数组")}, 
		returns=@ApiField("执行结果")
	)
	public static <T> T invoke(Object source, String methodName, Map<Integer, Class<?>> defaultParamClasses, Object...args){
		try {
			if(ObjectUtils.isEmpty(args)){
				return invoke(source, methodName);
			}
			ParamClass[] argsClassArray=getClassArray(defaultParamClasses, args);
			return (T)matchMethod(source.getClass(), methodName, args, argsClassArray).invoke(source, args);
		} catch(InvocationTargetException e) {
			Throwable targetException = ((InvocationTargetException) e).getTargetException();
			throw ExceptionUtils.exception("class.invoke.method.exception", targetException, source.getClass().getName(), methodName, targetException.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.exception("class.invoke.method.exception", e, source.getClass().getName(), methodName, e.getMessage());
		}
	}
	
	@ApiMethod(value="在反射类对象中匹配指定方法", params={@ApiField("反射类对象"), @ApiField("方法名称"), @ApiField("参数类对象，详见：ParamClass")}, returns=@ApiField("反射方法对象"))
	private static Method matchMethod(Class<?> source, String methodName, Object[] dataArgs, ParamClass...args){
		Method[] methods=source.getMethods();
		if(ObjectUtils.isEmpty(methods)){
			throw ExceptionUtils.message("class.find.method.exception", source.getName(), methodName);
		}
		Method equals=null;
		Class<?>[] paramTypes;
		boolean matchEqual=false,matchSimilar;
		int childIndex,length;
		Map<Method, Integer[]> similarMap=new HashMap<Method, Integer[]>();
		Integer[] similarArray;
		for (Method method : methods) {
			if(!method.getName().equals(methodName)){
				continue;
			}
			paramTypes=method.getParameterTypes();
			if(ObjectUtils.isEmpty(paramTypes)){
				continue;
			}
			length=paramTypes.length;
			if(length!=args.length){
				continue;
			}
			matchEqual=true;
			for (int i = 0; i < length; i++) {
				if(args[i].isMust() && !paramTypes[i].equals(args[i].getType())){
					matchEqual=false;
				}
			}
			if(!matchEqual){
				similarArray=new Integer[length];
				matchSimilar=true;
				for (int i = 0; i < length; i++) {
					if(!args[i].isMust()){
						childIndex=1;
					}else{
						childIndex=matchClass(args[i], paramTypes[i], dataArgs, i);
					}
					if(childIndex==0){
						matchSimilar=false;
						break;
					}else{
						similarArray[i]=childIndex;
					}
				}
				if(matchSimilar){
					similarMap.put(method, matchSimilar?similarArray:null);
				}
			}else{
				equals=method;
				break;
			}
		}
		if(matchEqual){
			return equals;
		}else if(ObjectUtils.isNotEmpty(similarMap)){
			Map<Integer, Method> methodIndexMap=new HashMap<Integer, Method>();
			int maxChildIndex=0, currChildIndex;
			for (Entry<Method, Integer[]> similar : similarMap.entrySet()) {
				currChildIndex=0;
				for (Integer integer : similar.getValue()) {
					currChildIndex+=integer;
				}
				if(currChildIndex>maxChildIndex){
					maxChildIndex=currChildIndex;
				}
				if(!methodIndexMap.containsKey(currChildIndex)){
					methodIndexMap.put(currChildIndex, similar.getKey());
				}
			}
			if(maxChildIndex>0){
				return methodIndexMap.get(maxChildIndex);
			}else{
				throw ExceptionUtils.message("class.find.method.exception", source.getName(), methodName);
			}
		}else{
			throw ExceptionUtils.message("class.find.method.exception", source.getName(), methodName);
		}
	}
	
	@ApiMethod(value="判断参数反射类对象，是否是另一个类的子类", params={@ApiField("参数反射类对象"), @ApiField("父类"), @ApiField("入参"), @ApiField("索引")}, returns=@ApiField("如果返回结果大于0，则是"))
	private static int matchClass(ParamClass source, Class<?> target, Object[] args, int index){
		if(source.isMust()){//是否必须
			Class<?> parentClass=source.getType();
			if(parentClass.equals(Integer.class)) {
				if(target.equals(Long.class)) {
					args[index]=Long.parseLong(args[index].toString());
					return 2;
				}
				if(target.equals(Float.class)) {
					args[index]=Float.parseFloat(args[index].toString());
					return 3;
				}
				if(target.equals(Double.class)) {
					args[index]=Double.parseDouble(args[index].toString());
					return 4;
				}
				if(target.equals(BigDecimal.class)) {
					args[index]=new BigDecimal(args[index].toString());
					return 4;
				}
			}
			int i=1;
			while(!parentClass.equals(Object.class)){
				if(parentClass.equals(target)){
					return i;
				}
				parentClass=parentClass.getSuperclass();
				i++;
			}
			if(parentClass.equals(target)){
				return i;
			}
		}else{//如果不是必须匹配，则直接返回，无需匹配，如果无法理解，请参考getClassArray方法
			return 1;
		}
		return 0;
	}
	
	@ApiMethod(value="根据参数反射类对象Map获取参数反射类对象数组，如果Map的key中包含参数值数组的索引，则为必须匹配，否则不是必须匹配", params={@ApiField("参数反射类对象Map"), @ApiField("参数值数组")})
	private static ParamClass[] getClassArray(Map<Integer, Class<?>> defaultParamClasses, Object...args){
		if(ObjectUtils.isEmpty(args)){
			return null;
		}
		ParamClass[] paramClasses=new ParamClass[args.length];
		for (int i = 0, length=args.length; i < length; i++) {
			if(ObjectUtils.isEmpty(args[i])){
				if(ObjectUtils.isNotEmpty(defaultParamClasses) && defaultParamClasses.containsKey(i)){
					paramClasses[i]=new ParamClass(defaultParamClasses.get(i), true);
				}else{
					paramClasses[i]=new ParamClass(Object.class, false);
				}
			}else{
				paramClasses[i]=new ParamClass(args[i].getClass(), true);
			}
		}
		return paramClasses;
	}
	
	@ApiMethod(value="将可变反射类对象参数转换为反射类对象数组", params=@ApiField("可变反射类对象参数"), returns=@ApiField("反射类对象数组"))
	public static Class<?>[] toArray(Class<?>...args){
		return args;
	}
	
	@ApiMethod(value="在对象中寻找指定属性路径的属性值，如果查找过程中有一个属性为null，则返回null", params={@ApiField("Pojo对象"), @ApiField("属性路径，格式为：field1.field2.field3...")}, returns=@ApiField("属性值，表示属性路径最末尾属性值"))
	public static <T> T getPathFieldValue(Object entity, String paths){
		return (T)getPathField(entity, paths).getFieldValue();
	}
	
	@ApiMethod(value="在对象中寻找指定属性路径的路径属性对象，如果查找过程中有一个属性为null，则返回包含null的PathField对象", params={@ApiField("Pojo对象"), @ApiField("属性路径，格式为：field1.field2.field3...")}, returns=@ApiField("路径属性对象，表示属性路径最末尾属性值的路径属性"))
	public static PathField getPathField(Object entity, String paths){
		try {
			if(ObjectUtils.isNull(entity)){
				return new PathField(null, null);
			}
			String[] pathArray=paths.split("\\.");
			Object temp=entity;
			String fieldName;
			int start,end,index=0;
			Field field;
			Class<?> fieldType=null;
			for (String path : pathArray) {
				fieldType=null;
				if(path.charAt(path.length()-1)==')'){//如果表达式形如：aaa(),则表示要执行方法
					start=path.indexOf("(");
					temp=invoke(temp, path.substring(0, start));
					if(ObjectUtils.isNotEmpty(temp)){
						fieldType=temp.getClass();
					}
				}else{
					if(temp instanceof Map){//如果在Map中获取属性
						start=path.indexOf("[");
						if(start!=-1){
							fieldName=path.substring(0, start);
							end=path.indexOf("]");
							index=Integer.parseInt(path.substring(start+1, end));
						}else{
							fieldName=path;
						}
						temp=((Map<?,?>)temp).get(fieldName);
						if(start!=-1){
							if(temp instanceof List){
								temp=((List<?>)temp).get(index);
								continue;
							}else if(temp.getClass().isArray()){
								temp=Array.get(temp, index);
								continue;
							}
							throw ExceptionUtils.message("class.parse.path.error", entity.getClass().getName(), paths);
						}
					}else{
						start=path.indexOf("[");
						if(start!=-1){
							fieldName=path.substring(0, start);
							end=path.indexOf("]");
							index=Integer.parseInt(path.substring(start+1, end));
						}else{
							fieldName=path;
						}
						field=ClassUtils.getField(temp.getClass(), fieldName);
						if(ObjectUtils.isNull(field)){
							throw ExceptionUtils.message("class.find.field.null", temp.getClass().getName(), fieldName);
						}
						fieldType=field.getType();
						field.setAccessible(true);
						temp=field.get(temp);
						if(start!=-1){
							if(temp instanceof List){
								temp=((List<?>)temp).get(index);
								continue;
							}else if(temp.getClass().isArray()){
								temp=Array.get(temp, index);
								continue;
							}
							throw ExceptionUtils.message("class.parse.path.error", entity.getClass().getName(), paths);
						}
					}
					if(ObjectUtils.isNull(temp)){
						return new PathField(null, ObjectUtils.isEmpty(fieldType)?Object.class:fieldType);
					}
				}
			}
			return new PathField(temp, ObjectUtils.isEmpty(fieldType)?Object.class:fieldType);
		} catch (CoreException e){
			throw e;
		} catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.message("class.parse.path.exception", entity.getClass().getName(), paths, e.getMessage());
		}
	}
	
	@ApiEntity(value="路径属性类", author="unswift", date="2022-12-16", version="1.0.0")
	public static class PathField{
		
		@ApiField("属性值")
		private Object fieldValue;
		
		@ApiField("属性反射类对象")
		private Class<?> fieldClass;
		
		@ApiConstructor(value="路径属性类唯一构造", params={@ApiField("属性值"), @ApiField("属性反射类对象")})
		public PathField(Object fieldValue, Class<?> fieldClass) {
			super();
			this.fieldValue = fieldValue;
			this.fieldClass = fieldClass;
		}
		public Object getFieldValue() {
			return fieldValue;
		}
		public void setFieldValue(Object fieldValue) {
			this.fieldValue = fieldValue;
		}
		public Class<?> getFieldClass() {
			return fieldClass;
		}
		public void setFieldClass(Class<?> fieldClass) {
			this.fieldClass = fieldClass;
		}
	}
	@ApiEntity(value="属性反射类对象封装类")
	static class ParamClass{
		
		@ApiField("反射类对象")
		private Class<?> type;
		
		@ApiField("是否必须匹配，true：必须匹配，false：不是必须匹配，此属性主要应用在，在匹配类方法时使用的规则")
		private boolean must;
		
		@ApiConstructor(value="属性反射类对象构造方法", params={@ApiField("反射类对象"), @ApiField("是否必须匹配，true：必须匹配，false：不是必须匹配")})
		public ParamClass(Class<?> type, boolean must) {
			this.type=type;
			this.must=must;
		}
		public Class<?> getType() {
			return type;
		}
		public void setType(Class<?> type) {
			this.type = type;
		}
		public boolean isMust() {
			return must;
		}
		public void setMust(boolean must) {
			this.must = must;
		}
	}
	
	@ApiMethod(value="将字符串转为指定该的java类型", params={@ApiField("字符串"), @ApiField("转换的反射类类型")})
	public static <T> T stringToBaseJava(String source, Class<T> type){
		Object value;
		if(type.equals(String.class)){
			value=(T)source;
		}else if(type.equals(Long.class) || type.equals(long.class)){
			value=Long.parseLong(source);
		}else if(type.equals(Integer.class) || type.equals(int.class)){
			value=Integer.parseInt(source);
		}else if(type.equals(Boolean.class) || type.equals(boolean.class)){
			value=Boolean.parseBoolean(source);
		}else if(type.equals(Date.class)) {
			value=DateUtils.parse(source);
		}else if(type.equals(Class.class)){
			value=ClassUtils.forName(source);
		}else{
			throw ExceptionUtils.message("string.to.class.type.not.implemented", source, type.getName());
		}
		return (T)value;
	}
	
	@ApiMethod(value="扫描指定包下的所有类", params={@ApiField("包路径，格式为com.xxx.xxx"), @ApiField("扫描回调，扫描到类则执行")})
	public static void scanningPackage(String basePackage, ScanningCallback callback){
		try {
			System.out.println(basePackage);
			ClassLoader loader=Thread.currentThread().getContextClassLoader();
			String packagePath=basePackage.replace(".", "/");
			Enumeration<URL> resources = loader.getResources(packagePath);
			URL url;
			String protocol;
			String pkgPath;
			File file;
			while(resources.hasMoreElements()){
				url=resources.nextElement();
				if(ObjectUtils.isEmpty(url)){
					continue;
				}
				protocol=url.getProtocol();
				pkgPath=url.getPath();
				if("file".equals(protocol)){
					file=new File(pkgPath);
					if(file.isDirectory()){
						scanningPackage(basePackage, file, callback);
					}else if(file.isFile() && StringUtils.endsWith(pkgPath, ".class")){
						callback.callback(basePackage+"."+file.getName().substring(0, file.getName().lastIndexOf(".class")));
					}
				} else if (protocol.equals("jar")) {
					JarFile jarFile = ((JarURLConnection) url.openConnection()).getJarFile();
					scanningPackage(packagePath, basePackage, jarFile, callback);
				}
			}
			
			
		} catch (CoreException e){
			throw e;
		} catch (Exception e) {
			e.printStackTrace();
			throw ExceptionUtils.exception("scanning.package.exception", e, e.getMessage());
		}
	}
	
	@ApiMethod(value="扫描文件", params={@ApiField("目录的包路径"), @ApiField("目录对象"), @ApiField("扫描回调，扫描到类则执行")})
	private static void scanningPackage(String folderPackage, File folder, ScanningCallback callback){
		File[] fileList=folder.listFiles();
		if(ObjectUtils.isEmpty(fileList)){
			return ;
		}
		for (File file : fileList) {
			if(file.isDirectory()){
				scanningPackage(folderPackage+"."+file.getName(), file, callback);
			}else if(file.isFile() && StringUtils.endsWith(file.getName(), ".class")){
				callback.callback(folderPackage+"."+file.getName().substring(0, file.getName().lastIndexOf(".class")));
			}
		}
	}
	
	@ApiMethod(value="扫描jar文件", params={@ApiField("搜索的包文件路径"), @ApiField("搜索的包路径"), @ApiField("jar对象"), @ApiField("扫描回调，扫描到类则执行")})
	private static void scanningPackage(String packagePath, String jarPackage, JarFile jarFile, ScanningCallback callback){
		Enumeration<JarEntry> entries = jarFile.entries();
		if(ObjectUtils.isEmpty(entries)){
			return ;
		}
		JarEntry entry;
		String name;
		String className;
		while(entries.hasMoreElements()){
			entry=entries.nextElement();
			name=entry.getName();
			if(!StringUtils.startsWith(name, packagePath) || !StringUtils.endsWith(name, ".class")){
				continue;
			}
			className=name.substring(0, name.lastIndexOf(".class")).replace("/", ".");
			callback.callback(className);
		}
	}
	
	@Api(value="扫描包回调", author="unswift", date="2022-12-24", version="1.0.0")
	public static abstract class ScanningCallback{
		
		@ApiMethod(value="回调方法，需使用者实现", params=@ApiField("类路径名称"), returns=@ApiField("是否继续扫描"))
		public boolean callback(String className){return true;}
		
	}
	
	@ApiMethod(value="根据类类型获取类声明", params = {@ApiField("类类型"), @ApiField("泛型参数")}, returns = @ApiField("类声明"))
	public static String getClassStatement(Class<?> clazz, Type[] paramArgs) {
		StringBuilder statement=new StringBuilder();
		statement.append(clazz.getName());
		TypeVariable<?>[] typeParameters = clazz.getTypeParameters();
		if(ObjectUtils.isNotEmpty(typeParameters)) {
			statement.append("<");
			int index=0;
			for (TypeVariable<?> typeVariable : typeParameters) {
				if(ObjectUtils.isEmpty(paramArgs)) {
					statement.append(typeVariable.getTypeName());
					Type[] bounds = typeVariable.getBounds();
					if(ObjectUtils.isNotEmpty(bounds)) {
						List<Type> boundList=ObjectUtils.asList(bounds).stream().filter(b -> !Object.class.equals(b)).collect(Collectors.toList());
						if(ObjectUtils.isNotEmpty(boundList)) {
							statement.append(" extends ");
							for (Type type : boundList) {
								if(type instanceof ParameterizedType) {
									ParameterizedType parameterizedType=(ParameterizedType)type;
									statement.append(getClassStatement((Class<?>)parameterizedType.getRawType(), parameterizedType.getActualTypeArguments())).append(", ");
								}else {
									statement.append(getClassStatement((Class<?>)type, null)).append(", ");
								}
							}
							int length = statement.length();
							statement.delete(length-2, length);
						}
					}
				}else {
					if(paramArgs[index] instanceof ParameterizedType) {
						ParameterizedType parameterizedType=(ParameterizedType)paramArgs[index];
						statement.append(getClassStatement((Class<?>)parameterizedType.getRawType(), parameterizedType.getActualTypeArguments()));
					}else {
						statement.append(paramArgs[index].getTypeName());
					}
				}
				statement.append(", ");
				index++;
			}
			int length = statement.length();
			statement.delete(length-2, length);
			statement.append(">");
		}
		return statement.toString();
	}
	
	
	@ApiMethod(value="根据类类型获取父类声明", params = @ApiField("类类型"), returns = @ApiField("父类声明"))
	public static String getSuperClassStatement(Class<?> clazz) {
		Type type = clazz.getGenericSuperclass();
		if(ObjectUtils.isEmpty(type)) {
			return null;
		}
		if(type instanceof ParameterizedType) {
			ParameterizedType parameterizedType=(ParameterizedType)type;
			return getClassStatement((Class<?>)parameterizedType.getRawType(), parameterizedType.getActualTypeArguments());
		}else {
			return getClassStatement((Class<?>)type, null);
		}
	}
	
	@ApiMethod(value="一个类是否是另一个类的父类", params = {@ApiField("类类型"), @ApiField("父类类型")}, returns = @ApiField("是否父类，true：是，false：否"))
	public static boolean isSuperClass(Class<?> sourceClass, Class<?> superClass) {
		return superClass.isAssignableFrom(sourceClass);
	}
	
	@ApiMethod(value="根据类类型获取父接口声明", params = @ApiField("类类型"), returns = @ApiField("父接口声明"))
	public static String getInterfacesClassStatement(Class<?> clazz) {
		Type[] interfaces = clazz.getGenericInterfaces();
		if(ObjectUtils.isEmpty(interfaces)) {
			return null;
		}
		StringBuilder statement=new StringBuilder();
		for (Type type : interfaces) {
			if(type instanceof ParameterizedType) {
				ParameterizedType parameterizedType=(ParameterizedType)type;
				statement.append(getClassStatement((Class<?>)parameterizedType.getRawType(), parameterizedType.getActualTypeArguments()));
			}else {
				statement.append(getClassStatement((Class<?>)type, null));
			}
			statement.append(", ");
		}
		int length = statement.length();
		statement.delete(length-2, length);
		return statement.toString();
	}
	
	@ApiMethod(value="查找指定注解类列表", params = {@ApiField("要扫描的包"), @ApiField("匹配的注解类列表（只匹配一个即可）")}, returns = @ApiField("匹配的类列表"))
	public static List<Class<?>> findAnnotationList(List<String> scanPackages, List<Class<? extends Annotation>> matchAnnotationClassList){
		ExceptionUtils.empty(scanPackages, "set.scanned.packages");
		PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
		MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
		Resource[] resources;
		Class<?> findClass;
		Object customAnno;
		List<Class<?>> findList=new ArrayList<Class<?>>();
		for (String scanPackage : scanPackages) {
			try {
				String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
	                    org.springframework.util.ClassUtils.convertClassNameToResourcePath(SystemPropertyUtils.resolvePlaceholders(scanPackage)) + "/" + DEFAULT_RESOURCE_PATTERN;
				resources = resolver.getResources(packageSearchPath);
				for (Resource resource : resources) {
					String clazz = loadClassName(metadataReaderFactory, resource);
					findClass=ClassUtils.forName(clazz);
					if(ObjectUtils.isNotEmpty(matchAnnotationClassList)) {
						for (Class<? extends Annotation> matchAnnotationClass : matchAnnotationClassList) {
							customAnno=findClass.getAnnotation(matchAnnotationClass);
							if(ObjectUtils.isNotEmpty(customAnno)) {
								findList.add(findClass);
							}
						}
					}else {
						findList.add(findClass);
					}
				}
			} catch (CoreException e) {
				throw e;
			} catch (Exception e) {
				e.printStackTrace();
				throw ExceptionUtils.exception("scanned.packages.error", e, e.getMessage());
			}
		}
		return findList;
	}
	
	@ApiMethod(value="将资源转为类路径", params = {@ApiField("spring MetadataReader 工厂"), @ApiField("spring io资源类")}, returns = @ApiField("类路径"))
	private static String loadClassName(MetadataReaderFactory metadataReaderFactory, Resource resource) {
        try {
            if (resource.isReadable()) {
                MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
                if (metadataReader != null) {
                    return metadataReader.getClassMetadata().getClassName();
                }
            }
        } catch (Exception e) {
        	e.printStackTrace();
			throw ExceptionUtils.exception("scanned.packages.error", e, e.getMessage());
        }
        return null;
    }
	
	@ApiMethod(value="在指定类类型中获取包含指定注解的方法", params = {@ApiField("指定类"), @ApiField("指定注解")}, returns = @ApiField("包含指定注解的方法"))
	public static List<Method> getAnnotationMethod(Class<?> sourceClass, Class<? extends Annotation> annotation){
		Method[] methods = sourceClass.getMethods();
		if(ObjectUtils.isNotEmpty(methods)) {
			return ObjectUtils.asList(methods).stream().filter(m -> ObjectUtils.isNotEmpty(m.getAnnotation(annotation))).collect(Collectors.toList());
		}
		return null;
	}
	
	@ApiMethod(value="解析类的属性", params = {
			@ApiField("类类型"), 
			@ApiField("属性转换的实体类类型"), 
			@ApiField("实体字段名称，长度为2，第一个为“属性名称”的字段名，第二个“属性描述”的字段名"),
			@ApiField("实体共有父类，如果遇到父类属性，则循环解析"),
			@ApiField("最大解析深度，默认为5，如果深度小于等于0或者大于等于10，则为5，否则指定深度"),
			@ApiField("已存在的字段集合，重复的则只返回一个")}, 
			returns = @ApiField("属性列表"))
	public static <E> List<E> getClassFieldList(Type type, Class<E> entityClass, String[] fieldNames, Class<?> superClass, int maxDepth, Set<String> existsFieldSet){
		ExceptionUtils.empty(fieldNames, "field.name.not.empty.and.length.equals.2");
		ExceptionUtils.trueException(fieldNames.length!=2, "field.name.not.empty.and.length.equals.2");
		maxDepth=maxDepth<0 || maxDepth>10?5:maxDepth;
		List<E> fieldList=new ArrayList<E>();
		Class<?> paramClass=null;
		Map<String, Type> paramMap=new HashMap<String, Type>();
		if(type instanceof ParameterizedType) {
			ParameterizedType paramType=(ParameterizedType)type;
			Type[] actualTypeArguments = paramType.getActualTypeArguments();
			Type rawType = paramType.getRawType();
			if(rawType instanceof Class){
				paramClass=(Class<?>)rawType;
				TypeVariable<?>[] typeParameters = paramClass.getTypeParameters();
				for (int j = 0; j < typeParameters.length; j++) {
					paramMap.put(typeParameters[j].getTypeName(), actualTypeArguments[j]);
				}
			}
		}else {
			paramClass=(Class<?>)type;
			if(!ClassUtils.isSuperClass(paramClass, superClass)) {
				return fieldList;
			}
		}
		if(ObjectUtils.isNotEmpty(paramClass)) {
			List<Field> fields=ClassUtils.getFieldList(paramClass);
			E customField;
			if(ObjectUtils.isNotEmpty(fields)) {
				ApiField fieldAnno;
				for (Field field : fields) {
					fieldAnno=field.getAnnotation(ApiField.class);
					if(ObjectUtils.isEmpty(fieldAnno)) {
						continue;
					}
					if(existsFieldSet.contains(field.getName())){
						continue;
					}
					if(field.getType().equals(List.class) && maxDepth!=0) {
						ParameterizedType paramType=(ParameterizedType)field.getGenericType();
						String typeName = paramType.getActualTypeArguments()[0].getTypeName();
						if(paramMap.containsKey(typeName)) {
							getClassFieldList(paramMap.get(typeName), entityClass, fieldNames, superClass, 0, maxDepth, fieldList, existsFieldSet, field.getName());
						}else {
							getClassFieldList(paramType.getActualTypeArguments()[0], entityClass, fieldNames, superClass, 0, maxDepth, fieldList, existsFieldSet, field.getName());
						}
					}else if(ClassUtils.isSuperClass(field.getType(), superClass)) {
						String typeName = field.getGenericType().getTypeName();
						if(paramMap.containsKey(typeName)) {
							getClassFieldList(paramMap.get(typeName), entityClass, fieldNames, superClass, 0, maxDepth, fieldList, existsFieldSet, field.getName());
						}else {
							getClassFieldList(field.getGenericType(), entityClass, fieldNames, superClass, 0, maxDepth, fieldList, existsFieldSet, field.getName());
						}
					}else {
						customField=ClassUtils.newInstance(entityClass);
						ClassUtils.set(customField, fieldNames[0], field.getName());
						ClassUtils.set(customField, fieldNames[1], fieldAnno.value());
						fieldList.add(customField);
						existsFieldSet.add(field.getName());
					}
				}
			}
		}
		return fieldList;
	}
	
	@ApiMethod(value="解析类的属性", params = {
			@ApiField("类类型"), 
			@ApiField("属性转换的实体类类型"), 
			@ApiField("实体字段名称，长度为2，第一个为“属性名称”的字段名，第二个“属性描述”的字段名"), 
			@ApiField("最大解析深度，默认为5，如果深度小于等于0或者大于等于10，则为5，否则指定深度"),
			@ApiField("最终的属性列表"),
			@ApiField("父属性路径")})
	private static <E> void getClassFieldList(Type type, Class<E> entityClass, String[] fieldNames, Class<?> superClass, int depth, int maxDepth, List<E> fieldList, Set<String> existsFieldSet, String parentPath){
		if(depth>=maxDepth) {//属性深度大于5级，则不解析了
			return ;
		}
		Class<?> paramClass=null;
		Map<String, Type> paramMap=new HashMap<String, Type>();
		if(type instanceof ParameterizedType) {
			ParameterizedType paramType=(ParameterizedType)type;
			Type[] actualTypeArguments = paramType.getActualTypeArguments();
			Type rawType = paramType.getRawType();
			if(rawType instanceof Class){
				paramClass=(Class<?>)rawType;
				TypeVariable<?>[] typeParameters = paramClass.getTypeParameters();
				for (int j = 0; j < typeParameters.length; j++) {
					paramMap.put(typeParameters[j].getTypeName(), actualTypeArguments[j]);
				}
			}
		}else {
			paramClass=(Class<?>)type;
			if(!ClassUtils.isSuperClass(paramClass, superClass)) {
				return ;
			}
		}
		if(ObjectUtils.isNotEmpty(paramClass)) {
			List<Field> fields=ClassUtils.getFieldList(paramClass);
			E customField;
			if(ObjectUtils.isNotEmpty(fields)) {
				ApiField fieldAnno;
				for (Field field : fields) {
					fieldAnno=field.getAnnotation(ApiField.class);
					if(ObjectUtils.isEmpty(fieldAnno)) {
						continue;
					}
					if(existsFieldSet.contains(field.getName())){
						continue;
					}
					if(field.getType().equals(List.class)) {
						
						
						
					}else if(ClassUtils.isSuperClass(field.getType(), superClass)) {
						String typeName = field.getGenericType().getTypeName();
						if(paramMap.containsKey(typeName)) {
							getClassFieldList(paramMap.get(typeName), entityClass, fieldNames, superClass, depth+1, maxDepth, fieldList, existsFieldSet, parentPath+"."+field.getName());
						}else {
							getClassFieldList(field.getGenericType(), entityClass, fieldNames, superClass, depth+1, maxDepth, fieldList, existsFieldSet, parentPath+"."+field.getName());
						}
					}else {
						customField=ClassUtils.newInstance(entityClass);
						ClassUtils.set(customField, fieldNames[0], parentPath+"."+field.getName());
						ClassUtils.set(customField, fieldNames[1], fieldAnno.value());
						fieldList.add(customField);
						existsFieldSet.add(field.getName());
					}
				}
			}
		}
	}
}
